#!/usr/bin/env python
# -*- coding: utf-8 -*-

import gdata.photos.service
import gdata.media
import gdata.geo

class photo:
  def __init__(self, user, passwd):
    self.gd_client = gdata.photos.service.PhotosService()
    self.gd_client.email = user
    self.gd_client.password = passwd
    self.gd_client.source = 'eBoutique'
    self.gd_client.ProgrammaticLogin()
    self.album = None
    
    albums = self.gd_client.GetUserFeed(user=user)

    for album in albums.entry:
      if album.title.text == 'eBoutique':
        self.album = album
        break
        
    if not self.album:
      self.album = self.gd_client.InsertAlbum(title='eBoutique',
       summary='This is an album for eBoutique application')
       
  def ListPhotos(self):
    photos = self.gd_client.GetFeed('/data/feed/api/user/%s/albumid/%s?kind=photo' % (self.gd_client.email, self.album.gphoto_id.text))
    return photos.entry

  def PostPhoto(self, filename):
    album_url = '/data/feed/api/user/%s/albumid/%s' % (self.gd_client.email, self.album.gphoto_id.text)
    photo = self.gd_client.InsertPhotoSimple(album_url, 'pp', 
                'Uploaded using the API', filename, content_type='image/jpeg')
    return photo.content.src

